import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { Global } from "../../../../com/gengine/global/Global";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { RollNumber } from "./RollNumber";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class CoinMonsterLotteryView
    
    export  class CoinMonsterLotteryView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.x = (Global.stage.stageWidth - 100) / 2;
            this.y = 100;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._bg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bg);
            LoaderManager.instance.load("MonsterLotteryBg.png", this.onLoadComplete);
            this._rollNumber1 = new RollNumber(5, 0.1, 1, 9);
            this._rollNumber2 = new RollNumber(4, 0.2);
            ObjCreate.setObjAttri(this._rollNumber1, 109, 32, -1, -1, this);
            ObjCreate.setObjAttri(this._rollNumber2, 141, 32, -1, -1, this);
            this._btnStop = ObjCreate.createGLoadedButton(ResFileConst.CoinCopyStopBtn, 93, 79, 58, 58, this);
            this._btnStop.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClick);
            this._rollNumber1.addEventListener(flash.events.Event.CLOSE, this.onClose);
            this._rollNumber2.addEventListener(flash.events.Event.CLOSE, this.onClose);
            return;
        }

        /* internal  */onLoadComplete(arg1): void
        {
            this._bg.bitmapData = arg1.bitmapData as Object /* flash.display.BitmapData */;
            return;
        }

        /* internal  */onBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.stop();
            return;
        }

        /* internal  */stop(): void
        {
            if (this._btnStop.enabled) 
            {
                this._rollNumber1.stop();
                this._rollNumber2.stop();
                this._btnStop.enabled = false;
            }
            return;
        }

        /* internal  */onClose(arg1: Object /* flash.events.Event */): void
        {
            if (!this._rollNumber1 || !this._rollNumber2) 
            {
                return;
            }
            var loc1;
            var loc2=((loc1 = this).closeNum + 1);
            loc1.closeNum = loc2;
            if (this.closeNum == 2) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CoinCopySetCoinNum, this._rollNumber1.currentNumber * 10 + this._rollNumber2.currentNumber));
                this.closeNum = 0;
            }
            return;
        }

        public startLotter(): void
        {
            this._rollNumber1.reset();
            this._rollNumber2.reset();
            this._rollNumber1.start();
            this._rollNumber2.start();
            this._btnStop.enabled = true;
            flash.utils.setTimeout(this.stop, 7000);
            return;
        }

        public resetPosition(): void
        {
            this.x = (Global.stage.stageWidth - 100) / 2;
            this.y = 100;
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnStop: GLoadedButton;

        /* internal */ /* var */_rollNumber1: RollNumber;

        /* internal */ /* var */_rollNumber2: RollNumber;

        /* internal */ /* var */closeNum: int=0;
    }
